package org.springboot.szsrcb.srvice;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springboot.szsrcb.entity.Attachment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

@Service
public class Query_Service {
	 private static final Logger logger = LoggerFactory.getLogger(Query_Service.class);
	 
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");



	public boolean add_a_date_as_working_date(Date date) {
		String tmp=sdf.format(date);
		String sql = "INSERT INTO working_date (working_date)VALUES(Date('"+tmp+"')); ";
		logger.info("从数据库执行" + sql);
		int r=jdbcTemplate.update(sql);
		if(r>0){
			return true;
		}else{
			return false;
		}
		
	}


	public double getDaySub(Date beginDate, Date endDate) {
		String tmp1=sdf.format(beginDate);
		String tmp2=sdf.format(endDate);
		String sql = "select count(*) from working_date where working_date>= Date('"+tmp1+"') and working_date<= Date('"+tmp2+"')";
		logger.info("从数据库执行" + sql);
		//RowMapper<T> a=new 
		List<Map<String, Object>> r=jdbcTemplate.queryForList(sql);
		if(r.size()>0){
		  double g=(long) r.get(0).get("count(*)");
		 return g;
		}
		return 0;
		
	}
	
	



}
